import React from 'react';
import { Alert } from 'react-native';
import { Scene, Actions } from 'react-native-router-flux';
import detail from '../models/customer';
import navBarStyle from '../../../components/navBarStyle';
import Form from "./Form";

const pressHandle = values => {
  detail.update(values).then(name => {
    if (name) {
      Alert.alert('操作成功', `更新客户${name}的资料`, [
        { text: '返回', onPress: Actions.pop }
      ]);
    }
  });
};

module.exports = (
  <Scene
    key="editCustomerExtra"
    component={(props) => <Form
      {...props}
      detail={detail}
      onSubmit={pressHandle}
    />}
    path="edit/customer/extra/:id"
    title="编辑客户附加信息"
    hideTabBar
    onEnter={props => {
      detail.getCustomer.call(detail, props.customerId);
    }}
    {...navBarStyle}
  />
);
